home *** CD-ROM | disk | FTP | other *** search
/ Aminet 49 / Aminet 49 (2002)(GTI - Schatztruhe)[!][Jun 2002].iso / Aminet / util / sys / AmberRAM.lha / AmberRAM / Source / notification.c < prev    next >
C/C++ Source or Header  |  2002-01-21  |  7KB  |  336 lines

  1. /*
  2.  
  3. File: notification.c
  4. Author: Neil Cafferkey
  5. Copyright (C) 2001-2002 Neil Cafferkey
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  20. MA 02111-1307, USA.
  21.  
  22. */
  23.  
  24.  
  25. #include "handler_protos.h"
  26.  
  27.  
  28.  
  29. /****i* ram.handler/MatchNotifyRequests ************************************
  30. *
  31. *   NAME
  32. *    MatchNotifyRequests --
  33. *
  34. *   SYNOPSIS
  35. *    MatchNotifyRequests(handler)
  36. *
  37. *    VOID MatchNotifyRequests(struct Handler *);
  38. *
  39. *   FUNCTION
  40. *
  41. *   INPUTS
  42. *
  43. *   RESULT
  44. *
  45. *   EXAMPLE
  46. *
  47. *   NOTES
  48. *
  49. *   BUGS
  50. *
  51. *   SEE ALSO
  52. *
  53. ****************************************************************************
  54. *
  55. */
  56.  
  57. VOID MatchNotifyRequests(struct Handler *handler)
  58. {
  59.    struct Notification *notification,*tail;
  60.  
  61.    notification=(APTR)handler->notifications.mlh_Head;
  62.    tail=(APTR)&handler->notifications.mlh_Tail;
  63.  
  64.    while(notification!=tail)
  65.    {
  66.       notification->object=
  67.          GetObject(handler,NULL,notification->request->nr_FullName,NULL);
  68.       notification=(APTR)((struct MinNode *)notification)->mln_Succ;
  69.    }
  70.  
  71.    return;
  72. }
  73.  
  74.  
  75.  
  76. /****i* ram.handler/NotifyAll **********************************************
  77. *
  78. *   NAME
  79. *    NotifyAll --
  80. *
  81. *   SYNOPSIS
  82. *    NotifyAll(handler,object,notify_links)
  83. *
  84. *    VOID NotifyAll(struct Handler *,struct Object *,BOOL);
  85. *
  86. *   FUNCTION
  87. *
  88. *   INPUTS
  89. *
  90. *   RESULT
  91. *
  92. *   EXAMPLE
  93. *
  94. *   NOTES
  95. *
  96. *   BUGS
  97. *
  98. *   SEE ALSO
  99. *
  100. ****************************************************************************
  101. *
  102. */
  103.  
  104. VOID NotifyAll(struct Handler *handler,struct Object *object,
  105.    BOOL notify_links)
  106. {
  107.    struct Notification *notification,*tail;
  108.    struct Object *request_object,*link;
  109.    struct MinNode *link_tail,*link_node;
  110.    BOOL found;
  111.  
  112.    if(notify_links)
  113.    {
  114.       object=GetRealObject(object);
  115.       link_tail=object->hard_link.mln_Pred;
  116.       if(link_tail==NULL)
  117.          notify_links=FALSE;
  118.    }
  119.  
  120.    notification=(APTR)handler->notifications.mlh_Head;
  121.    tail=(APTR)&handler->notifications.mlh_Tail;
  122.  
  123.    while(notification!=tail)
  124.    {
  125.       request_object=notification->object;
  126.       if(request_object!=NULL)
  127.       {
  128.          if(notify_links)
  129.          {
  130.             link_node=&object->hard_link;
  131.             found=FALSE;
  132.  
  133.             while((link_node!=link_tail)&&!found)
  134.             {
  135.                link=HARDLINK(link_node);
  136.  
  137.                if((request_object==link)||(request_object==link->parent))
  138.                   found=TRUE;
  139.  
  140.                link_node=link_node->mln_Succ;
  141.             }
  142.          }
  143.          else
  144.             found=
  145.                (request_object==object)||(request_object==object->parent);
  146.  
  147.          if(found)
  148.             Notify(handler,notification);
  149.       }
  150.       notification=(APTR)((struct MinNode *)notification)->mln_Succ;
  151.    }
  152.  
  153.    return;
  154. }
  155.  
  156.  
  157.  
  158. /****i* ram.handler/FindNotification ***************************************
  159. *
  160. *   NAME
  161. *    FindNotification --
  162. *
  163. *   SYNOPSIS
  164. *    notification = FindNotification(handler,
  165. *        request)
  166. *
  167. *    struct Notification *FindNotification(struct Handler *,
  168. *        struct NotifyRequest);
  169. *
  170. *   FUNCTION
  171. *
  172. *   INPUTS
  173. *
  174. *   RESULT
  175. *
  176. *   EXAMPLE
  177. *
  178. *   NOTES
  179. *
  180. *   BUGS
  181. *
  182. *   SEE ALSO
  183. *
  184. ****************************************************************************
  185. *
  186. */
  187.  
  188. struct Notification *FindNotification(struct Handler *handler,
  189.    struct NotifyRequest *request)
  190. {
  191.    struct Notification *notification,*tail;
  192.    BOOL found;
  193.  
  194.    notification=(APTR)handler->notifications.mlh_Head;
  195.    tail=(APTR)&handler->notifications.mlh_Tail;
  196.    found=FALSE;
  197.  
  198.    while((notification!=tail)&&!found)
  199.    {
  200.       if(notification->request==request)
  201.          found=TRUE;
  202.       else
  203.          notification=(APTR)((struct MinNode *)notification)->mln_Succ;
  204.    }
  205.  
  206.    if(!found)
  207.       notification=NULL;
  208.  
  209.    return notification;
  210. }
  211.  
  212.  
  213.  
  214. /****i* ram.handler/ReceiveNotifyReply *************************************
  215. *
  216. *   NAME
  217. *    ReceiveNotifyReply --
  218. *
  219. *   SYNOPSIS
  220. *    ReceiveNotifyReply(handler,message)
  221. *
  222. *    VOID ReceiveNotifyReply(struct Handler *,struct NotifyMessage *);
  223. *
  224. *   FUNCTION
  225. *
  226. *   INPUTS
  227. *
  228. *   RESULT
  229. *
  230. *   EXAMPLE
  231. *
  232. *   NOTES
  233. *
  234. *   BUGS
  235. *
  236. *   SEE ALSO
  237. *
  238. ****************************************************************************
  239. *
  240. */
  241.  
  242. VOID ReceiveNotifyReply(struct Handler *handler,
  243.    struct NotifyMessage *message)
  244. {
  245.    struct Notification *notification;
  246.    struct NotifyRequest *request;
  247.  
  248.    request=message->nm_NReq;
  249.    notification=FindNotification(handler,request);
  250.    FreeMem(message,sizeof(struct NotifyMessage));
  251.  
  252.    if(notification!=NULL)
  253.    {
  254.       request->nr_MsgCount--;
  255.  
  256.       if(request->nr_Flags&NRF_MAGIC)
  257.       {
  258.          request->nr_Flags&=~NRF_MAGIC;
  259.          Notify(handler,notification);
  260.       }
  261.    }
  262.  
  263.    return;
  264. }
  265.  
  266.  
  267.  
  268. /****i* ram.handler/Notify *************************************************
  269. *
  270. *   NAME
  271. *    Notify --
  272. *
  273. *   SYNOPSIS
  274. *    Notify(handler,notification)
  275. *
  276. *    VOID Notify(struct Handler *,struct Notification *);
  277. *
  278. *   FUNCTION
  279. *
  280. *   INPUTS
  281. *
  282. *   RESULT
  283. *
  284. *   EXAMPLE
  285. *
  286. *   NOTES
  287. *
  288. *   BUGS
  289. *
  290. *   SEE ALSO
  291. *
  292. ****************************************************************************
  293. *
  294. */
  295.  
  296. VOID Notify(struct Handler *handler,struct Notification *notification)
  297. {
  298.    struct NotifyMessage *message;
  299.    struct NotifyRequest *request;
  300.    ULONG flags;
  301.  
  302.    request=notification->request;
  303.    flags=request->nr_Flags;
  304.    if(flags&NRF_SEND_MESSAGE)
  305.    {
  306.       message=AllocMem(sizeof(struct NotifyMessage),MEMF_PUBLIC|MEMF_CLEAR);
  307.       if(message!=NULL)
  308.       {
  309.          ((struct Message *)message)->mn_ReplyPort=handler->notify_port;
  310.          ((struct Message *)message)->mn_Length=
  311.             sizeof(struct NotifyMessage);
  312.          message->nm_NReq=request;
  313.          message->nm_Class=NOTIFY_CLASS;
  314.          message->nm_Code=NOTIFY_CODE;
  315.  
  316.          if((flags&NRF_WAIT_REPLY)&&(request->nr_MsgCount!=0))
  317.             request->nr_Flags|=NRF_MAGIC;
  318.          else
  319.          {
  320.             PutMsg(request->nr_stuff.nr_Msg.nr_Port,(APTR)message);
  321.             request->nr_MsgCount++;
  322.          }
  323.       }
  324.    }
  325.    else
  326.    {
  327.       Signal(request->nr_stuff.nr_Signal.nr_Task,
  328.          1<<(request->nr_stuff.nr_Signal.nr_SignalNum));
  329.    }
  330.  
  331.    return;
  332. }
  333.  
  334.  
  335.  
  336.